import request from '@/utils/request'
// 根据部门ID获取项目树
export function projectTree(query) {
  return request({
    url: '/common/projectTree',
    method: 'get',
    params: query
  })
}

// 根据项目ID获取楼栋
export function buildingList(query) {
  return request({
    url: '/common/buildingList',
    method: 'get',
    params: query
  })
}
// 业务角色
export function roleList(query) {
  return request({
    url: '/common/businessRoleList',
    method: 'get',
    params: query
  })
}
// 根据业务角色ID获取用户
export function userList(query) {
  return request({
    url: '/common/userList',
    method: 'get',
    params: query
  })
}

// 获取组织与项目
/*
* query type 0 1 2
* */
export function getDeptProject(query) {
  return request({
    url: '/common/deptTree',
    method: 'get',
    timeout: 30000,
    params: query
  })
}

// 获取字典
export function getEnum(dictName) {
  return request({
    url: '/common/dict',
    method: 'get',
    params: { dictName: dictName }
  })
}

// 根据用户获取权限项目
export function getAuthCurProject() {
  return request({
    url: '/common/getAuthCurProject',
    method: 'get',
    timeout: 60000
  })
}

// 获取事业部
export function getBusinessDivision() {
  return request({
    url: '/common/businessDivision',
    method: 'get'
  })
}

/**
 * 获取工序树
 * @return {*}
 */
export function getCheckTableTree(query) {
  return request({
    url: '/common/checkTableTree',
    method: 'get',
    params: query
  })
}

// 统一文件上传接口
export const FILE_UPLOAD_URL = process.env.VUE_APP_BASE_API + '/file/upload'
// 批量上传
export const FILE_MULTI_UPLOAD_URL = process.env.VUE_APP_BASE_API + '/file/multiUpload'

/**
 * 文件下载/图片显示链接
 * @param {String | Number} fileId
 * @param {Number} [cacheTime] 默认缓存一天，设为0则不缓存
 * @returns {String} URL
 */
export const getFileURL = (fileId, cacheTime) => `${process.env.VUE_APP_BASE_API}/file/download?fileKey=${fileId}&cacheTime=${cacheTime || 864e5}`

// 下载文件公共方法
export function downloadFile(fileId, cacheTime) {
  return request({
    timeout: 30000,
    url: `/file/download?fileKey=${fileId}&cacheTime=${cacheTime || 864e5}`,
    method: 'get',
    responseType: 'arraybuffer'
  }, {
    source: true
  })
}
